﻿using System;
using System.Collections.Generic;
using System.Text;

namespace RootFinding
{
    public class SimpleRootFinder : IRootFinder
    {
        #region IRootFinder Members

        public double Solve(string expr, double l, double h)
        {
            double r = 0;
            MathExpressionParser mep = new MathExpressionParser();
            UnaryFunction f = mep.Parse(expr);

            BisectionRootFinder finder 
                = new BisectionRootFinder(f, Int32.MaxValue, 0);

            try
            {
                r = finder.Solve(0, double.MaxValue, 0, true);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return r;
        }

        #endregion
    }
}
